﻿using System;
using System.Linq;
using System.Web.UI.WebControls;
using App_Code;
public partial class _default : System.Web.UI.Page
{
    dulieuDataContext db=new dulieuDataContext();
    protected void Page_Load(object sender, EventArgs e)
    {
        if (IsPostBack) return;
        LoadSanPhamBanChay();
        LoadSanPhamMoiNhat();
        LoadThoiTrangTreEm();
        LoadPhuKienVaMyPham();
        LoadSpaVaLamDep();
        LoadQuanAn();
        LoadGocGiaDinh();
        LoadSachVaTruyen();
        LoadKhoaHoc();
        LoadDienMay();
    }
    protected void LoadSanPhamBanChay()
    {
        rpt_san_pham_ban_chay.DataSource = (from o in db.Products orderby o.ProductID descending where o.Cate_ID == 125 select o);
        //rpt_san_pham_ban_chay.DataSource =(from o in db.Products orderby o.Count descending select o).Take(15);
        rpt_san_pham_ban_chay.DataBind();
    }
    protected void LoadSanPhamMoiNhat()
    {
        rpt_san_pham_moi_nhat.DataSource = (from o in db.Products orderby o.ProductID descending where o.Cate_ID == 129 select o);
        rpt_san_pham_moi_nhat.DataBind();
    }
    protected void LoadThoiTrangTreEm()
    {
        rpt_thoi_trang_tre_em.DataSource = (from o in db.Products orderby o.ProductID descending where o.Cate_ID == 131 select o);
        rpt_thoi_trang_tre_em.DataBind();
    }
    protected void LoadPhuKienVaMyPham()
    {
        rpt_phu_kien_my_pham.DataSource = (from o in db.Products orderby o.ProductID descending where o.Cate_ID == 135 select o);
        rpt_phu_kien_my_pham.DataBind();
    }
    protected void LoadSpaVaLamDep()
    {
        rpt_spa_lam_dep.DataSource = (from o in db.Products orderby o.ProductID descending where o.Cate_ID == 137 select o);
        rpt_spa_lam_dep.DataBind();
    }
    protected void LoadQuanAn()
    {
        rpt_quan_an.DataSource = (from o in db.Products orderby o.ProductID descending where o.Cate_ID == 138 select o);
        rpt_quan_an.DataBind();
    }

    protected void LoadGocGiaDinh()
    {
        rpt_goc_gia_dinh.DataSource = (from o in db.Products orderby o.ProductID descending where o.Cate_ID == 139 select o);
        rpt_goc_gia_dinh.DataBind();
    }
    protected void LoadSachVaTruyen()
    {
        rpt_sach_truyen.DataSource = (from o in db.Products orderby o.ProductID descending where o.Cate_ID == 141 select o);
        rpt_sach_truyen.DataBind();
    }
    protected void LoadKhoaHoc()
    {
        rpt_khoa_hoc.DataSource = (from o in db.Products orderby o.ProductID descending where o.Cate_ID == 143 select o);
        rpt_khoa_hoc.DataBind();
    }
    protected void LoadDienMay()
    {
        rpt_dien_may.DataSource = (from o in db.Products orderby o.ProductID descending where o.Cate_ID == 144 select o);
        rpt_dien_may.DataBind();
    }
    protected void BuyClick(object s,CommandEventArgs e)
    {
        var idpr = e.CommandName;
        var cart = (Cart) Session["cart"];
        if (cart==null)
        {
            cart=new Cart();
        }
        cart.AddPro(idpr,1);
        Session.Add("cart",cart);
        Response.Write(string.Format("<SCRIPT language='JavaScript'>alert('Đã thêm vào giỏ hàng!');window.location.href='{0}';</SCRIPT>",Server.HtmlEncode(Request.RawUrl)));
    }
}